package com.scisoft.scan.control.pack;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.scisoft.scan.dy.R;
import com.scisoft.scan.data.pack.PackInfoBean;

import java.util.List;

public class PackInfoAdapter extends BaseAdapter {
    private List<PackInfoBean> packInfoBeanList;//数据源
    private LayoutInflater mInflater;//布局装载器对象

    public PackInfoAdapter(List<PackInfoBean> packInfoBeanList, Context context){
        this.packInfoBeanList=packInfoBeanList;
        mInflater = LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        //return返回的是int类型，也就是页面要显示的数量。
        return packInfoBeanList.size();
    }
    @Override
    public Object getItem(int position) {
        return packInfoBeanList.get(position);
    }
    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //将布局文件转化为View对象
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_packinfo,null);
        }
        //单号
        TextView tv_orderNo = convertView.findViewById(R.id.tv_orderNo);
        //地址
        TextView tv_address= convertView.findViewById(R.id.tv_address);
        //统计明细
        TextView tv_detail= convertView.findViewById(R.id.tv_detail);
        //操作信息
        TextView tv_opinfo = convertView.findViewById(R.id.tv_opinfo);
        //订单类型
        TextView tv_orderType  = convertView.findViewById(R.id.tv_orderType);
        //联系人
        TextView tv_contact  = convertView.findViewById(R.id.tv_contact);
        //订单金额
        TextView tv_amount  = convertView.findViewById(R.id.tv_amount);
        //客户
        TextView tv_customerName  = convertView.findViewById(R.id.tv_customerName);
        //包装区域
        TextView tv_packArea = convertView.findViewById(R.id.tv_packArea);

        //获取相应索引的ItemBean对象
        PackInfoBean bean = packInfoBeanList.get(position);

        //设置控件的对应属性值
        tv_orderNo.setText(bean.orderNo);
        tv_address.setText(bean.depotName);
        tv_detail.setText(bean.detail);
        tv_opinfo.setText(bean.operator + "     " + bean.optime);
        tv_orderType.setText(bean.orderType);
        tv_contact.setText(bean.contact);
        tv_amount.setText(bean.amount);
        tv_customerName.setText(bean.customerName);
        tv_packArea.setText(bean.packArea);

        return convertView;
    }
}
